package com.dao;
import com.pojo.BookReview;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import java.util.List;
import java.util.Map;

public interface BookReviewDao {
    @Insert("insert into book_review values(null,#{userId},#{bookName},#{score},#{review},#{time});")
    void add(BookReview bookReview);

    @Select("select * from book_review order by time desc limit #{page},#{pageSize};")
    List<Map> queryPage(int page,int pageSize);

    @Select("select * from book_review" +
            " where bookName like #{queryString} or userId in" +
            "(select id from user where nickName like #{queryString})" +
            "order by time desc limit #{page},#{pageSize};")
    List<Map> queryPageByParam(int page, int pageSize, String queryString);

    @Select("select count(*) from book_review;")
    int getCount();

    @Select("<script> select*from book_review where userId in <foreach item='item' index='index' collection='userIds' open='(' separator=',' close=')'> #{item}</foreach>order by time desc;</script>")
    List<Map> getByUserIds(List<Integer> userIds);

    @Select("select*from book_review where bookName like #{bookName};")
    List<Map> getByBookName(String bookName);

}
